package com.xk857.system.mapper;

import com.xk857.entities.SysMenu;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 菜单信息表 Mapper 接口
 *
 * @author CV大魔王
 * @since 2021-02-25
 */
public interface SysMenuMapper extends BaseMapper<SysMenu> {


    /**
     * 查询指定用户ID的所拥有的权限（目录、菜单、按钮）
     * @param userId 用户id
     * @return 用户的菜单列表
     */
    @Select("SELECT DISTINCT m.id,m.parent_id,m.NAME,m.CODE,m.url,m.type,m.icon,m.remark,m.sort,m.create_date,m.update_date FROM sys_user AS u JOIN sys_user_role AS ur ON u.id = ur.user_id JOIN sys_role AS r ON ur.role_id = r.id JOIN sys_role_menu AS rm ON rm.role_id = r.id JOIN sys_menu AS m ON rm.menu_id = m.id WHERE u.id = #{userId} ORDER BY m.sort")
    List<SysMenu> findByUserId(@Param("userId") String userId);

}
